Map generated for Health Project

library(tidyverse)
## ── Attaching packages ────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.3.2     ✔ purrr   0.3.4
## ✔ tibble  3.0.1     ✔ dplyr   1.0.0
## ✔ tidyr   1.1.0     ✔ stringr 1.3.1
## ✔ readr   1.1.1     ✔ forcats 0.3.0
## ── Conflicts ───────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(gsheet)

data <- read_csv("historical.csv") %>% 
  mutate(date = mdy(Date)) %>% 
  mutate(year = year(date)) 
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   OBJECTID = col_integer(),
##   FID_ = col_integer(),
##   Building_C = col_integer(),
##   Tree_Tag_N = col_integer(),
##   DBH = col_double(),
##   Number_of_ = col_integer(),
##   Percentage = col_integer(),
##   Crown_Widt = col_double(),
##   Total_Heig = col_double(),
##   Latitude = col_double(),
##   Longitude = col_double(),
##   Height_to_ = col_double(),
##   Unbalanced = col_integer(),
##   Reduced_Cr = col_integer(),
##   Weak_Yello = col_integer(),
##   Defoliatio = col_integer(),
##   Dead_Broke = col_integer(),
##   Poor_Branc = col_integer(),
##   Lean = col_integer(),
##   Trunk_Scar = col_integer()
##   # ... with 9 more columns
## )
## See spec(...) for full column specifications.
health <- read.csv("tree_health.csv")

df <-  data %>% 
  select(7, 9:11, DBH, 18, 32, 30, 28, year, 20, 21) %>% 
  rename(TreeID = Tree_Tag_N, species = 2, common = 3, genus = 4, crown_width = 6, conks = 7, scars = 8,
  branch_health = 9) 

final <-  merge(df, health, by = "TreeID" )

DBH Maps

library(ggmap)
## Warning: package 'ggmap' was built under R version 3.5.2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(geosphere)
## Warning: package 'geosphere' was built under R version 3.5.2
register_google(key="AIzaSyBurG6FR6I4uc_nRUr6TY118dCsnM0tsiE")
York <- get_map(location = c(lon = -79.502469, lat = 43.773388), zoom = 15, maptype = "satellite")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=43.773388,-79.502469&zoom=15&size=640x640&scale=2&maptype=satellite&language=en-EN&key=xxx
York
## 1280x1280 satellite map image from Google Maps. 
## See ?ggmap to plot it.
map <- ggmap(York)
map <- map +
  geom_point(data=final, aes(x=Longitude, y=Latitude, color = DBH), alpha = 1, size =0.1, shape = 0, show.legend = TRUE) +
  labs(x = "longitude", y = "latitude") + theme(axis.title.x = element_blank()) + theme(axis.title.y = element_blank())
map + scale_color_gradient(low = "yellow", high = "red")

register_google(key="AIzaSyBurG6FR6I4uc_nRUr6TY118dCsnM0tsiE")
York <- get_map(location = c(lon = -79.502469, lat = 43.773388), zoom = 15)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=43.773388,-79.502469&zoom=15&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
York
## 1280x1280 terrain map image from Google Maps. 
## See ?ggmap to plot it.
map <- ggmap(York)
map <- map +
  geom_point(data=final, aes(x=Longitude, y=Latitude, color = DBH), alpha = 1, size =0.1, shape = 0, show.legend = TRUE) +
  labs(x = "longitude", y = "latitude") + theme(axis.title.x = element_blank()) + theme(axis.title.y = element_blank())
map + scale_color_gradient(low = "yellow", high = "red")

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.